package com.yuanfengerp.customersettlemer.controller;

import com.yuanfengerp.customersettlemer.model.CustomerSettlementInfo;
import com.yuanfengerp.customersettlemer.service.impl.CustomerSettlementServiceImpl;
import com.yuanfengerp.publicUtil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class CustomerSettlementController {
    @Autowired
    private CustomerSettlementServiceImpl cssi;

    /**
     * 获取所有客户结算信息
     * 此方法响应GET请求，从服务器端查询并返回所有客户结算信息的集合
     *
     * @return 返回包含所有客户结算信息的字符串
     */
    @GetMapping("/selectAllCustomerSettlement")
    public String selectAllCustomerSettlement() {
        return cssi.selectAllCustomerSettlement().toString();
    }

    /**
     * 根据参数查询客户结算信息
     * 此方法响应POST请求，根据传入的参数查询客户结算信息
     *
     * @param params 查询参数的Map集合，包含查询条件
     * @return 返回根据参数查询到的客户结算信息的字符串
     */
    @PostMapping("/selectCustomerSettlement")
    public Result<List<CustomerSettlementInfo>> selectCustomerSettlement(@RequestBody Map<String, Object> params) {
        System.out.println(params.toString());
        return cssi.selectCustomerSettlement(params);
    }

    /**
     * 插入新的客户结算信息
     * 此方法响应POST请求，向数据库中插入一条新的客户结算信息
     *
     * @param customerSettlementInfo 要插入的客户结算信息对象
     * @return 返回表示插入结果的字符串
     */
    @PostMapping("/insertCustomerSettlement")
    public Result<String> insertCustomerSettlement(@RequestBody CustomerSettlementInfo customerSettlementInfo) {
        return cssi.insertCustomerSettlement(customerSettlementInfo);
    }

    /**
     * 删除指定ID的客户结算信息
     * 此方法响应POST请求，根据客户结算信息的ID从数据库中删除对应的记录
     *
     * @param customer_settlement_ID 要删除的客户结算信息的ID
     * @return 返回表示删除结果的字符串
     */
    @PostMapping("/deleteCustomerSettlement")
    public String deleteCustomerSettlement(String customer_settlement_ID) {
        return cssi.deleteByPrimaryKey(customer_settlement_ID).toString();
    }

    /**
     * 批量删除客户结算信息
     * 此方法响应POST请求，根据一组客户结算信息的ID从数据库中批量删除对应的记录
     *
     * @param customer_settlement_IDs 要批量删除的客户结算信息的ID列表
     * @return 返回表示批量删除结果的字符串
     */
    @PostMapping("/batchdeleteCustomerSettlement")
    public String batchdeleteCustomerSettlement(ArrayList<String> customer_settlement_IDs) {
        return cssi.batchdelete(customer_settlement_IDs).toString();
    }

    /**
     * 批量审核客户结算信息
     * 此方法响应POST请求，根据一组客户结算信息的ID对这些记录进行批量审核
     *
     * @param customer_settlement_IDs 要批量审核的客户结算信息的ID列表
     * @return 返回表示批量审核结果的字符串
     */
    @PostMapping("/batchreviewCustomerSettlement")
    public String batchreviewCustomerSettlement(ArrayList<String> customer_settlement_IDs) {
        return cssi.batchreview(customer_settlement_IDs).toString();
    }

    /**
     * 更新客户结算信息
     * 此方法响应POST请求，更新数据库中某条客户结算信息的详细内容
     *
     * @param customerSettlementInfo 要更新的客户结算信息对象，包含修改后的信息
     * @return 返回表示更新结果的字符串
     */
    @PostMapping("/updateCustomerSettlement")
    public String updateCustomerSettlement(@RequestBody CustomerSettlementInfo customerSettlementInfo) {
        return cssi.updateCustomerSettlement(customerSettlementInfo).toString();
    }
    @PostMapping("/selectCustomerSettlementItemInfo")
    public Result<List
            <CustomerSettlementInfo>> selectCustomerSettlementItemInfo(String customer_settlement_ID) {
        return cssi.selectCustomerSettlementItemInfo(customer_settlement_ID);
    }

}
